package com.wutuo.aggragation.wtservice.controller;

import cn.apestar.core.base.BaseMessage;
import com.wutuo.wtservice.api.ServiceAPIService;
import com.wutuo.wtservice.api.request.ServiceRequest;
import com.wutuo.wtservice.api.response.ServiceResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 服务表 <br>
 * 详细说明.
 * <p>
 *
 * @author lvh
 * @version 1.0
 */
@RestController @RequestMapping(value = "/service", produces = "application/json")
public class ServiceController {

    private Logger logger = LoggerFactory.getLogger(ServiceController.class);

    @Autowired private ServiceAPIService serviceService;

    /**
     * 新增服务表
     *
     * @param request
     */
    @RequestMapping(value = "/addorUpdate", method = RequestMethod.POST) public Object create(
        @RequestBody @Valid ServiceRequest request) {

        serviceService.addorUpdate(request);
        return new BaseMessage();
    }

    /**
     * 删除服务表
     *
     * @param id
     */
    @RequestMapping(value = "/del/{id}", method = RequestMethod.GET) public Object del(
        @PathVariable("id") Long id) {

        serviceService.del(id);
        return new BaseMessage();
    }

    /**
     * 查询服务表
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/list/{id}", method = RequestMethod.GET)
    public List<ServiceResponse> lisForPage(@PathVariable("id") Long id) {

        ServiceRequest s = new ServiceRequest();
        s.setCmInstitutionId(id);
        s.setDelFlag(true);
        List list = serviceService.list(s);
        return list;
    }
}